package com.kclm.spring;

import com.kclm.pojo.User;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;



/**
 * @Author : lvhx
 * @Date: 2025/10/31 10:59
 * @Description:
 */
public class SpringTest {

    public void test1(){

        // 获取spring容器
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        User user = (User)applicationContext.getBean("user");
        System.out.println(user);
    }

    public static void main(String[] args) {
        Logger logger = LoggerFactory.getLogger(SpringTest.class);
        logger.info("我是一条日志消息");
//        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans.xml");
//        UserService  userService =(UserService) applicationContext.getBean("userService");
//        System.out.println(userService);
//        System.out.println(applicationContext.getBean("date"));
//        System.out.println(applicationContext.getBean("userService"));
//        System.out.println(applicationContext.getBean("userService2"));

        // 获取spring容器
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
//        User user = (User)applicationContext.getBean("user");
        User user = applicationContext.getBean("user", User.class);
        System.out.println(user);
        logger.info("我第二条日志消息==>{}",user);
//        System.out.println("===");
    }
}
